using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml.Serialization;

namespace WebApplication
{
	[Serializable]
	public class Tiles : ICollection
	{
		private ArrayList	_aTiles;

		public Tile this [string index]   // indexer declaration
		{ 
			get
			{
				Tile	returnTile = null;

				foreach (Tile tile in _aTiles)
				{
					if (tile.Name == index)
					{
						returnTile = tile;
						break;
					}

				}

				return returnTile;
			}
		}

		public Tile this [int index]   // indexer declaration
		{ 
			get
			{
				return (Tile) _aTiles[index];
			}

			set
			{
				_aTiles[index] = value;
			}
		}

		public void CopyTo(Array a, int index)
		{
			_aTiles.CopyTo(a, index);
		}
		public object SyncRoot
		{
			get{return this;}
		}
		public bool IsSynchronized
		{
			get{return false;}
		}

		public int Count
		{
			get
			{
				return _aTiles.Count;
			}
		}

		public Tiles ()
		{
			_aTiles = new ArrayList ();
		}

		public void Add (System.Object TileCompany)
		{
			_aTiles.Add (TileCompany);
		}

		public void Add (Tile Tile)
		{
			_aTiles.Add (Tile);
		}

		public void Remove (Tile Tile)
		{
			_aTiles.Remove (Tile);
		}

		// IEnumerable Interface Implementation:

		public IEnumerator GetEnumerator() // non-IEnumerable version
		{
			return _aTiles.GetEnumerator ();
		}

		IEnumerator IEnumerable.GetEnumerator() // IEnumerable version
		{
			//			return (IEnumerator) new TileEnumerator(this);
			return _aTiles.GetEnumerator ();
		}
	}

	[Serializable]
	public class Tile
	{
		private bool _upgradeHasNewTrack;

		public bool UpgradeHasNewTrack
		{
			get { return _upgradeHasNewTrack; }
			set { _upgradeHasNewTrack = value; }
		}

		private Hashtable /*MyDictionary<Side, SideCollection>*/ _routes;

		public Hashtable /*MyDictionary<Side, SideCollection>*/ Routes
		{
			get { return _routes; }
		}

		public enum eTileColor
		{
			Yellow, Green, Brown, Gray
		}
		
		public enum eTileTownType
		{
			Unpopulated, City, Town, DblTown 
		}

		// initial values
		private string				m_sName;		// Actually, the tile number  23, 24, 25, etc...
		private int					m_nQuantity;
		private eTileColor			m_eColor;
		private eTileTownType 			m_eTownType;
		private string				m_sFile;
		private StringCollection	_validUpgrades;
		private StringCollection	_validDowngrades;
		private string				_tileName;	// OO, Toronto, etc...
		private int					_worth;		// Value, but value is overloaded, so I'm using worth.  For example, tile 15, a green city, is worth 30.

		public int Worth
		{
			get { return _worth; }
			set { _worth = value; }
		}

		public string TileName
		{
			get { return _tileName; }
			set { _tileName = value; }
		}

			public StringCollection ValidUpgrades
		{
			get { return _validUpgrades; }
		}

		public StringCollection ValidDowngrades
		{
			get { return _validDowngrades; }
		}

		// runtime values
		private int			_nQuantityLeft;

		public int QuantityLeft
		{
			get { return _nQuantityLeft; }
			set { _nQuantityLeft = value; }
		}

		public Tile()
		{
		}
		
		public Tile(string sName, int nQuantity, eTileColor eColor, string sFile)
		{
			m_sName			= sName;
			m_nQuantity		= nQuantity;
			m_eColor		= eColor;
			m_sFile			= sFile;
			
			_nQuantityLeft	= nQuantity;
			_routes = new Hashtable /*MyDictionary<Side, SideCollection>*/();
			_validUpgrades = new StringCollection ();
			_validDowngrades = new StringCollection ();
			_upgradeHasNewTrack = true;		// All except green to brown Toronto in 1856 and New York in 1830 so far.
			_tileName = "";
		}

		public eTileColor Color
		{
			get { return m_eColor; }
			set { m_eColor = value; }
		}
		
		public string Name
		{
			get	{ return m_sName; }
		}
		
		public int Quantity
		{
			get	{ return m_nQuantity; }
		}
		
		public string File
		{
			get	{ return m_sFile; }
		}

		public eTileTownType TownType
		{
			get { return m_eTownType; }
			set { m_eTownType = value; }
		}
	}		
}
